#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e5+5;
int n,c,ans,cnt,b[N],k[N];
vector<int> a[N];
unordered_map<int,int> mp;
inline void del(int x){
	ans-=mp[x]*b[mp[x]];
	mp[x]--;
	ans+=mp[x]*b[mp[x]];
}
struct Node{
	vector<int> pos;
	int len=0,cnt=0;
	Node(){ }
};
signed main(){
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>k[i];
		a[i].resize(k[i]+1);
		for(int j=1;j<=k[i];j++){
			cin>>a[i][j];
			mp[a[i][j]]++;
			if(j>1 && a[i][j]<=a[i][j-1]){
				cout<<"what are you doing???\n";
			}
		}
	}
	cin>>c;
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	int cost=0;
	for(int i=1;i<=n;i++){
		ans+=c*k[i];
		cost+=k[i];
	}
	for(auto p:mp){
		ans+=p.second*b[p.second];
	}
	vector<pair<int,int>> pre;
	vector<Node> gap;
	for(int i=1;i<=n;i++){
		if(k[i]) cnt++;
		for(int j=2;j<=k[i];j++){
			pre.emplace_back(make_pair(a[i][j]-a[i][j-1]+1,a[i][j]));
		}
	}
	sort(pre.begin(),pre.end());
	int lst=1;
	Node cur;
	for(auto p:pre){
		if(p.first!=lst){
			if(cur.cnt) gap.push_back(cur);
			cur=Node(),cur.len=p.first;
		}
		cur.cnt++,lst=p.first;
		cur.pos.push_back(p.second);
	}
	gap.push_back(cur);
	vector<pair<int,int>> res;
	res.push_back((make_pair(ans,1)));
	lst=1;
	for(auto p:gap){
		ans+=(p.len-lst-1)*p.cnt*c;
		cost-=p.cnt;
		ans+=(p.len-lst)*cost*c;
		lst=p.len;
		for(int plc:p.pos) del(plc);
		if(lst) res.push_back(make_pair(ans,p.len));
	}
	sort(res.begin(),res.end());
	cout<<res[0].first<<" ";
	vector<int> pos;
	for(auto p:res){
		if(p.first==res[0].first) pos.push_back(p.second);
	}
	cout<<pos.size()<<"\n";
	for(int x:pos){
		cout<<x<<" ";
	}
}
//why pure implementation?
